import logging
import sys


def _get_logger():
    log = logging.getLogger('log')
    log.setLevel(logging.INFO)
    formatter = logging.Formatter('[%(levelname)s][%(asctime)s][%(filename)s:%(lineno)d] - %(message)s',
                                                  datefmt='%Y-%m-%d %H:%M:%S')
    # 配置输出日志到终端的 Handler
    stream_handler = logging.StreamHandler()
    stream_handler.setFormatter(formatter)
    # 配置保存日志到文件的 Handler
    file_handler = logging.FileHandler("internal_server.log", encoding='utf-8')
    file_handler.setFormatter(formatter)
    # 添加 Handler
    # log.addHandler(file_handler)
    log.addHandler(stream_handler)
    return log


# 日志句柄
logger = _get_logger()